<?php
namespace Account;
class UserController extends BaseController {
	function index() {
		$this->profile();
	}
	
	/**
	 * 修改资料
	 */
	public function profile(){
		if ($this->checkFormSubmit()){
			$accountnew = $_GET['accountnew'];
			$profilenew = $_GET['profilenew'];
			if (isemail($accountnew['email']) || ismobile($accountnew['mobile'])){
				member_update_data(array('uid'=>$this->uid), $accountnew);
			}
				
			$profilenew['locked'] = 1;
			$profilenew['modified'] = TIMESTAMP;
			member_update_profile($this->uid, $profilenew);
			$this->showSuccess('modi_succeed');
		}else {
			global $G,$lang;
			$account = member_get_data(array('uid'=>$this->uid));
			$profile = member_get_profile($this->uid);
			include template('profile');
		}
	}
	
	/**
	 * 修改密码
	 */
	public function password(){
		if ($this->checkFormSubmit()){
			$password    = trim($_GET['password']);
			$newpassword = trim($_GET['newpassword']);
			if ($password && $newpassword){
				$account = member_get_data(array('uid'=>$this->uid));
				if ($account['password'] !== sha1(md5($password))){
					$this->showError('old_password_error');
				}else {
					member_update_data(array('uid'=>$this->uid), array('password'=>sha1(md5($newpassword))));
					$this->showSuccess('modi_succeed');
				}
			}else {
				$this->showError('new_password_error');
			}
		}else {
			global $G,$lang;
			include template('password');
		}
	}
	
	/**
	 * 账户绑定
	 */
	public function bind(){
		
	}
}